package com.deng.dubbo.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.deng.dubbo.library.IUserService;
import com.deng.dubbo.library.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author DengLibin
 * @Date 19-5-15
 * @Time 下午5:57
 * @Desc
 */
@SuppressWarnings("unchecked")
@Component //spring注解
//dubbo服务注解 version:版本 weight:权重(部署到多个服务器时 负载均衡)
@Service(version = "1.0", interfaceClass = IUserService.class, weight = 1)
public class UserServiceImpl implements IUserService {
    private List<User> userList = new ArrayList();

    public UserServiceImpl(){
        userList.add(new User("张三",1));
        userList.add(new User("李四",2));
        userList.add(new User("王五",3));
    }
    @HystrixCommand
    @Override
    public User getById(int id) {
        return userList.get(id);
    }
}
